<template>
  <div class="admin-home">
    <div style="width: 100%;display: flex;justify-content: center;">
      <div class="div-1">
        <span style="font-size: 25px;font-weight: bold;">热招岗位</span>
        <div v-for="item in jobList" :key="item.jobId" class="div-1-item">
          <a-avatar :src="'http://localhost:8080/file/download?name='+item.jobCompanyLogo"
                    style="width: 70px; height: 70px;flex-shrink: 0;"/>
          <div style="display: flex;flex-wrap: wrap;">
            <div style="display: flex;align-items: center;padding-top: 10px;justify-content: space-between;width: 100%">
              <h3 style="margin-right: 10px;margin-left: 10px">
                <router-link :to="{path:'/student/job/detail/'+item.jobId}" style="color: #108ee9">{{
                    item.jobTitle
                  }}
                </router-link>
              </h3>
              <h5 style="margin-right: 10px;">薪资: {{ item.jobSalary }}</h5>
            </div>
            <div style="color: #333333">
              <h5 style="margin-right: 10px;margin-left: 10px">
                要求: {{ item.jobEducationRequirement }} &nbsp {{ item.jobMajorRequirement }}
                &nbsp 地点: {{ item.jobLocation }}
              </h5>
            </div>
          </div>
        </div>
      </div>
      <div style="width: 50%;height: auto;">
        <div class="carousel" style=" width: 100%;height: auto; ">
          <a-carousel autoplay>
            <div class="carousel-item"><img alt="" src="../../../assets/image/img1.jpg"></div>
            <div class="carousel-item"><img alt="" src="../../../assets/image/img2.jpg"></div>
            <div class="carousel-item"><img alt="" src="../../../assets/image/img3.jpg"></div>
            <div class="carousel-item"><img alt="" src="../../../assets/image/img4.png"></div>
            <div class="carousel-item"><img alt="" src="../../../assets/image/img5.png"></div>
          </a-carousel>
        </div>
      </div>
      <div class="div-1">
        <span style="font-size: 25px;font-weight: bold;">热门企业</span>
        <div v-for="item in enterpriseList" :key="item.enterpriseId" class="div-1-item">
          <a-avatar :src="'http://localhost:8080/file/download?name='+item.enterpriseLogoUrl"
                    style="width: 70px; height: 70px;flex-shrink: 0;"/>
          <div style="display: flex;flex-wrap: wrap;">
            <div style="display: flex;align-items: center;padding-top: 10px;justify-content: space-between;width: 100%">
              <h3 style="margin-right: 10px;margin-left: 10px">
                <!--                <router-link style="color: #108ee9" :to="{path:'/enterprise/info/'+item.enterpriseId}">-->
                {{ item.enterpriseName }}
                <!--                </router-link>-->
              </h3>
              <h5 style="margin-right: 10px">规模: {{ item.enterpriseSize }}</h5>
            </div>
            <div>
              <h5 style="margin-right: 10px;margin-left: 10px">
                行业: {{ item.enterpriseIndustry }}
                &nbsp 地点: {{ item.enterpriseAddress }}
              </h5>
            </div>
          </div>
        </div>
      </div>
    </div>

    <!--    公告-->
    <div style="width: 100%;display: flex;justify-content: center;">

      <div style="padding-left: 20px;padding-right: 20px;">
        <div>
          <a-modal v-model:open="open" :title=textTitle width="1000px">
            <span v-html="truncateText1(textContent)"></span>
            <template #footer>
              <a-button key="submit" type="primary" @click="handleOk">关闭</a-button>
            </template>
          </a-modal>
        </div>
        <div
            style="width: 100%;height: auto; border-radius: 20px;padding-bottom: 20px;padding-top: 20px; box-shadow: 0 0 5px rgba(0, 0, 0, 0.3);">
          <a-input-search
              v-model:value="data.searchName"
              allow-clear
              enter-button
              placeholder="输入公告标题"
              size="middle"
              style="width: 30%; padding: 10px;margin-left: 8px;"
              @search="onSearch"
          />
          <span style="font-size: 25px;font-weight: bold;margin-left: 17%">求职-干货</span>
          <div class="div-2">
            <a-list :data-source="listData" :pagination="pagination"
                    size="small"
                    style="width: 100%;margin-bottom: 30px;padding-right: 20px"
            >
              <template #renderItem="{ item }">
                <a-list-item :key="item.bulletinTitle" class="list-item">
                  <a-card :title="item.bulletinTitle" style="width: 100%">
                    <template #extra>
                      <a-button type="link" @click="showModal(item.bulletinId)">查看</a-button>
                    </template>
                    <span v-html="truncateText2(item.bulletinText)"></span>
                  </a-card>
                </a-list-item>
              </template>
            </a-list>
          </div>
        </div>
      </div>
    </div>
  </div>

</template>
<script setup>
import {queryHotJobAPI} from "@/apis/job.js";
import {onMounted, ref} from "vue";
import {getHotEnterpriseListAPI} from "@/apis/enterprise.js";

//1.获取热招岗位
const jobList = ref([]);
const getHotJobList = async () => {
  await queryHotJobAPI().then(res => {
    jobList.value = (res.data.data)
  })
}
//2.获取热门企业
const enterpriseList = ref([]);
const getHotEnterpriseList = async () => {
  await getHotEnterpriseListAPI().then(res => {
    enterpriseList.value = (res.data.data)
  })
}
// 生命周期
onMounted(() => {
  getHotJobList()
  getHotEnterpriseList()
});
//公告
//公告栏
// 新增方法用于将回车替换微br空格替换微&nbsp
const truncateText1 = (text) => {
  return text.replace(/\n/g, '<br>').replace(/ /g, '&nbsp;');
};
// 新增方法用于截断文本并添加省略号
const truncateText2 = (text) => {
  return text.slice(0, 20) + '. . . . .';
};
const open = ref(false);
const textContent = ref('');
const textTitle = ref('');
const showModal = async (bulletinId) => {
  open.value = true;
  const res = await queryBulletinDetailByIdAPI(bulletinId)
  if (res.data.flag) {
    textContent.value = res.data.data.bulletinText
    textTitle.value = res.data.data.bulletinTitle
  }
};
const handleOk = () => {
  open.value = false;
};
import {
  pageBulletinAPI,
  queryBulletinDetailByIdAPI,
} from "@/apis/bulletin.js";

const listData = ref([]);
const data = ref({pageCurrent: 1, pageSize: 6, searchName: '',});
const getData = async (data) => {
  const res = await pageBulletinAPI(data)
  pagination.total = res.data.data.total
  listData.value = res.data.data.data
}
const pagination = {
  onChange: page => {
    console.log(page);
    data.value.pageCurrent = page
    getData(data.value)
  },
  pageSize: 6,
  total: 0,
};


// 生命周期
onMounted(() => {
  getData(data.value);
});

//搜索
const onSearch = searchValue => {
  console.log('use value', searchValue);
  getData(data.value);
};

</script>
<style lang="scss" scoped>
.admin-home {
  height: auto;
  margin: -20px;

  .div-1 {
    display: flex;
    height: auto;
    margin-bottom: 30px;
    width: 25%;
    flex-direction: column; /* 设置主轴方向为垂直方向，子元素就会往下排列 */
    justify-content: center; /* 在主轴（现在是垂直方向）上居中对齐 */
    align-items: center; /* 在交叉轴（现在是水平方向）上居中对齐 */
    .div-1-item {
      border-radius: 20px;
      margin-top: 10px;
      display: flex;
      width: 90%;
      box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2); /* 添加阴影效果，这里的参数分别表示水平偏移量、垂直偏移量、模糊半径和阴影颜色的透明度 */
    }
  }

  .carousel-item {
    height: 400px;
    background-color: white;
    border-radius: 20px;
    border: 2px solid black;

    img {
      width: 100%;
      height: 100%;
      object-fit: cover;
    }
  }

  .list-item {
    width: 28%;
    margin: 20px;
    display: inline-block; // 让列表项横排显示，设置为行内块元素
    vertical-align: top; // 让列表项顶部对齐，视觉上更整齐，可选设置
    &:last-child {
      margin-right: 0; // 最后一个列表项去掉右侧间距，可选优化
    }
  }

  // 如果内部的 a-card 等元素宽度超出了父容器宽度，也需要设置其能自动换行
  a-card {
    display: block; // 确保内部卡片元素占满一行宽度等情况，可根据实际调整
    word-break: break-all; // 允许单词内换行，避免内容过长超出不换行情况
    width: 100%;
  }
}


:deep(.slick-slide) {
  text-align: center;
  line-height: 160px;
  background: #364d79;
  overflow: hidden;
}

:deep(.slick-arrow.custom-slick-arrow) {
  width: 25px;
  height: 25px;
  font-size: 25px;
  color: #fff;
  background-color: rgba(31, 45, 61, 0.11);
  transition: ease all 0.3s;
  opacity: 0.3;
  z-index: 1;
}

:deep(.slick-arrow.custom-slick-arrow:before) {
  display: none;
}

:deep(.slick-arrow.custom-slick-arrow:hover) {
  color: #fff;
  opacity: 0.5;
}


</style>